package com.Controller;

import com.Service.CategoryService;
import com.Utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/Category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @GetMapping("/findAllCategory")
    public R findAllCategory(){
        return new R(true,categoryService.findAllCategory());
    }

    @PostMapping("/addCategory")
    public R addCategory(@RequestBody Map<String,String> Map_All){
        String category1=Map_All.get("newCategory1");
        String category2=Map_All.get("newCategory2");
        System.out.println(category1);
        return new R(categoryService.addCategory(category1,category2)>0);
    }
    @PostMapping("/delCategory")
    public R delCategory(@RequestBody Map<String,String> Map_All){
        String category1=Map_All.get("category1");
        String category2=Map_All.get("category2");
        return new R(categoryService.delCategory(category1,category2)>0);
    }
    @PostMapping("/updataCategory")
    public R updataCategory(@RequestBody Map<String,String> Map_All){
        String category1=Map_All.get("category1");
        String category2=Map_All.get("category2");
        String newCategory1=Map_All.get("newCategory1");
        String newCategory2=Map_All.get("newCategory2");
        return new R(categoryService.updataCategory(category1,category2,newCategory1,newCategory2)>0);
    }

}
